<template>
    <div>
            <Card>
                <p slot="title">
				    新增基础类型
			    </p>
                <div>
                    <Form class="step-form" ref="basicTypeList" :model="basicTypeList" :rules="basicTypeRules" :label-width="100">
                        <Row span="12">
                            <i-col span="6" >
                                <FormItem label="类型名称："  prop="typeName" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="basicTypeList.typeName" type="text" placeholder="请输入类型名称" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="6" >
                                <FormItem label="类型数据："  prop="typeValue" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="basicTypeList.typeValue" type="text" placeholder="请输入类型数据" />
                                </FormItem>
                            </i-col>
                        </Row>

                        <FormItem >
                            <Button :disabled="hasSubmit" @click="handleSubmit" style="width:100px;" type="primary">提交</Button>
                        </FormItem>
                    </Form>
                </div>
            </Card>
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    name: 'addBasicType',
    data () {
        return {
            basicTypeList: {
                userId: '',
                userName: '',
                typeName: '',
                typeValue: ''
            },
            basicTypeRules: {
                typeName: [
                    { required: true, message: '请输入类型名称', trigger: 'blur'},
                    {type: 'string', max: 15, message: '不能超过15个字符', trigger: 'blur'}
                ],
                typeValue: [
                    { required: true, message: '请输入类型数据', trigger: 'blur'},
                    {type: 'string', max: 15, message: '不能超过15个字符', trigger: 'blur'}
                ],
            },
            hasSubmit: false,
            status: 'wait'
        }
    },
    methods: {
        init () {
            // 数据初始化
        },
        handleSubmit () {
            console.log(this.basicType)
            this.basicTypeList.userId = window.localStorage.getItem('userId')
            this.basicTypeList.userName = window.localStorage.getItem('userName')

            this.$refs['basicTypeList'].validate((valid) => {
                if (valid) {
                    this.hasSubmit = true
                    let url = '/adminapi/basictype/addBasicType.html'
                    let data = this.basicTypeList
                    console.log('-----------------data---------------------')
                    console.log(data)
                    ajax.formRes(url, data).then(res => {
                        // success
                        console.log('****************************')
                        this.$Message.success('新增症状成功,页面正在跳转')
                        let vm = this
                        setTimeout(function () {
                            vm.hasSubmit = false
                            vm.$router.push({
                                name: 'basictypeindex'
                            })
                        }, 1500)
                        vm.emptyData()
                    }).catch(res => {
                        console.log('有错误信息')
                        // fail
                    })
                } else {
                    console.log('新增症状失败。。。')
                }
            })
        },
        emptyData () {
            this.basicTypeList.typeName = ''
            this.basicTypeList.typeValue = ''
        }
    },
    created: function () {
        this.init()
    }
}
</script>
<style>
.zhengzhuangbuwei .ivu-form-item-required .ivu-form-item-content{margin-left: 0px !important;}
</style>
